

import { Controller, Get, Post, Body, UsePipes, UseGuards, SetMetadata, UseInterceptors } from '@nestjs/common';
import { Cat } from './interfaces/cat.interface';
import { CatsService } from './cats.service';
import { CatCreateDto } from './dto/cat-create.dto';
import { ValidationPipe } from '../pipe/validate.pipe';
import { Roles } from 'src/decorators/roles.decorator';
import { LoggingInterceptor } from 'src/interceptor/logging.interceptor';
import { ConfigService } from '@nestjs/config';
// import { RolesGuard } from 'src/guard/roles.guard';

// @UseFilters(new HttpExceptionFilter())
@Controller('cats')
// @UseGuards(new RolesGuard())
  @UseInterceptors(LoggingInterceptor)
export class CatsController {
  constructor(private catsService: CatsService, private configService: ConfigService) { }

  @Post('create')
  @Roles('admin')
  @UsePipes(new ValidationPipe())
  async create(@Body() catCreateDto: CatCreateDto) {
    // throw new HttpException('Forbidden1', HttpStatus.FORBIDDEN);
    console.log('config-port', this.configService.get('port'))
    console.log('config-dbHost', this.configService.get<string>('database.port'))
    try {
      this.catsService.create(catCreateDto);
      return true
    } catch (error) {
      return false
    }
  }

  @Get()
  async findAll(): Promise<Cat[]> {
    return this.catsService.findAll();
  }
}
